package com.njit.farm.controller;

import com.njit.farm.model.Goods;
import com.njit.farm.model.Result;
import com.njit.farm.service.GoodsService;
import javafx.geometry.Pos;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/goods/")
public class GoodsController {

    @Resource
    GoodsService goodsService;


    @RequestMapping(value = "add",method = RequestMethod.POST)
    public Result add(@RequestBody Goods goods){

        return goodsService.add(goods);
    }

    @RequestMapping(value = "getAll", method = RequestMethod.GET)
    public Result getAll() {
        return  goodsService.getAll();
    }

    @RequestMapping(value = "delete", method = RequestMethod.GET)
    public Result delete(@RequestParam("gId") String gid) {
        return goodsService.remove(gid);
    }

    @RequestMapping(value = "getByUserId", method = RequestMethod.GET)
    public Result getByUserId(@RequestParam("uId") String uId) {
        return goodsService.queryByUserId(uId);
    }

    @RequestMapping(value = "get", method = RequestMethod.GET)
    public Result get(@RequestParam("gId") String gId) {
        return goodsService.getGoods(gId);
    }
}
